package cn.itsource.ymcc.producer;

import cn.itsource.ymcc.domain.Course;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

//我们要发送消息
@Component
public class CourseMessageImpl implements CourseMessageProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    //同步  异步  单项  事务  延迟
    @Override
    public void sendMessage(Course course) {
        rocketMQTemplate.sendOneWay(CourseMessageProducer.TOPIC_COURSE_SEND_MESSAGE_SMS+":"+CourseMessageProducer.TAGS_COURSE_SEND_MESSAGE_SMS,
                MessageBuilder.withPayload(JSON.toJSONString(course)).build());
    }
}
